var app = getApp()
var axios = require("../../utils/core")
Page({
    /**
     * 页面的初始数据
     */
    data: {
        time: [], //存储秒杀时间后计算的数据
        goods_id: null,
        userinfo: null,
        teamid: null,
        data: [],
        setIntervaltime: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (e) {
        console.log(e);
        app.checkAuth();
        var that = this
        that.setData({
            userinfo: wx.getStorageSync('userinfo'),
            teamid: e.teamid,
            mid: e.mid
        })
        //开始时间戳,结束时间戳
        that.get_details(that.data.teamid)
    },
    to_d() {
        var d = this
        //点击成功助力
        console.log(d.data.mid);
        axios.post("groups/order/create_order", {
            zzz: d.data.mid,
            id: d.data.data.goods.id,
            group_option_id: d.data.option_id,
            ladder_id: d.data.ladder_id,
            type: "groups",
            heads: 0,
            teamid: d.data.teamid,
            zczlstatus: 1,
        }, function (t) {
            // t = t.parseInt()
            if (t.error == 1) {
                wx.showModal({
                    content: t.message,
                    showCancel: false
                })
            } else {
                wx.showToast({
                    title: '助力成功',
                })
                setTimeout(() => {
                    wx.navigateTo({
                        // url: '/groups/groups_detail/index?teamid=' + d.data.teamid,
                        url: '/other/Myhelp/Myhelp',
                    })
                }, 1500)
            }
            console.log(t, "助力商品");

        });
        setTimeout(() => {
            axios.post("groups/team/details", {
                teamid: d.data.teamid,
                zczlstatus: 1,
                mid: this.data.mid
            }, ((e) => {
                console.log(e, "助力进度");
            }))
        }, 1000)
    },
    joinTeam: function (o) {
        t.checkAuth();
        var e = this;
        wx.getSetting({
            success: function (t) {
                if (getApp().getCache("userinfo_openid")) {
                    var d = a.pdata(o).type,
                        s = a.pdata(o).op;
                    if (e.setData({
                            optionarr: [],
                            selectSpecsarr: []
                        }), "creat" == s ? e.setData({
                            op: "creat"
                        }) : e.setData({
                            op: ""
                        }), "ladder" == d) {
                        var i = e.data.data.id;
                        a.get("groups.goods.goodsCheck", {
                            id: i,
                            type: "group"
                        }, function (t) {
                            0 == t.error ? e.setData({
                                layershow: !0,
                                chosenum: !0
                            }) : wx.showToast({
                                title: t.message,
                                icon: "none",
                                duration: 2e3
                            });
                        });
                    } else if (0 == e.data.data.more_spec) {
                        i = e.data.data.id;
                        a.get("groups.goods.goodsCheck", {
                            id: i,
                            type: "group"
                        }, function (t) {
                            0 == t.error ? "creat" == s ? wx.navigateTo({
                                url: "../confirm/index?type=groups&id=" + i + "&heads=1"
                            }) : a.get("groups.goods.check_tuan", {
                                id: i,
                                type: "group"
                            }, function (t) {
                                t.data.order_num <= 0 ? a.alert("暂无拼团") : wx.navigateTo({
                                    url: "../jointeam/index?id=" + i
                                });
                            }) : wx.showToast({
                                title: t.message,
                                icon: "none",
                                duration: 2e3
                            });
                        });
                    } else {
                        i = e.data.data.id;
                        a.get("groups.goods.goodsCheck", {
                            id: i,
                            type: "group"
                        }, function (t) {
                            0 == t.error ? (a.get("groups.goods.get_spec", {
                                id: i
                            }, function (t) {
                                e.setData({
                                    spec: t.data
                                });
                            }), e.setData({
                                layershow: !0,
                                options: !0
                            })) : wx.showToast({
                                title: t.message,
                                icon: "none",
                                duration: 2e3
                            });
                        });
                    }
                }
            }
        });
    },
    get_details: function (t) {
        var that = this;
        axios.get("groups/team/details", {
            teamid: t
        }, function (e) {
            that.setData({
                data: e.data,
                setIntervaltime: setInterval(() => {
                    that.countDown(that.data.data.goods.endtime, that.data.data.goods.createtime)
                }, 1000)
            })
        });
    },
    countDown: function (t, a) {
        var o = parseInt(Date.now() / 1e3),
            s = parseInt((t > o ? t : a) - o),
            i = Math.floor(s / 86400),
            d = Math.floor((s - 24 * i * 60 * 60) / 3600),
            n = Math.floor((s - 24 * i * 60 * 60 - 3600 * d) / 60),
            r = Math.floor(s - 24 * i * 60 * 60 - 3600 * d - 60 * n);
        0 == i && 0 == d && 0 == n && 0 == r && this.get_details(this.data.teamid);
        var u = [i, d, n, r];
        this.setData({
            time: u
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var that = this
        var userinfo = wx.getStorageSync('userinfo')
        that.setData({
            userinfo: userinfo,
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        clearInterval(this.data.setIntervaltime)
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})